<template>
  <div class="myContainer">        
     <el-row class="myTitleBorderBottom">
      <el-col :span="20" class="myLineHeight_40px">
        基本信息
      </el-col>
    </el-row>
    <el-form :model="detail" :rules="rules" ref="ruleForm">
    	
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         用户ID:
      </el-col>
      <el-col :span="7">
        
            <el-input :readonly="is_modifly" v-model="person_id" placeholder="请输入用户ID"></el-input>
          
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         账号（电话号码）:
      </el-col>
      <el-col :span="7">
      	
           <el-input placeholder="请输入账号（电话号码）" v-model="login_name" :readonly="is_modifly"></el-input>
        
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
       <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
        可见光照片 :
      </el-col>
      <el-col :span="7">
        <el-upload
          class="avatar-uploader"
          :disabled="is_modifly"
          :action="responseUrl"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarUpload">
          <img v-if="imageUrl" :src="imageUrl" class="avatar">
          <i v-else class="el-icon-plus avatar-uploader-icon"></i>
        </el-upload>       
      </el-col>
    </el-row>
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         IC卡号:
      </el-col>
      <el-col :span="7">
       
            <el-input :readonly="is_modifly" v-model="ic_number" placeholder="请输入IC卡号"></el-input>
          
      </el-col>
    </el-row>
   
    <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         用户区域信息:
      </el-col>
     <el-col :span="7">
       
            <el-input :readonly="is_modifly" type="textarea"  v-model="area_name" placeholder="请输入用户区域信息"></el-input>
          
      </el-col>
    </el-row>
  
    <el-row class="myTitleBorderBottom myMarginTop_10px">
        <el-col :span="20" class="myLineHeight_40px">
          身份信息
        </el-col>
    </el-row>   
      <el-row class="myMarginTop_10px" :gutter="10">
        <el-col :span="3" class="myTextAlignRight myLineHeight_40px">
          用户性别 :
        </el-col>
        <el-col :span="7" class="myLineHeight_40px">
          <template>
            <el-radio-group v-model="sex" :disabled="is_modifly">
              <el-radio :label="1">男</el-radio>
              <el-radio :label="0">女</el-radio>
            </el-radio-group>
          </template>
        </el-col>
      </el-row>
     <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         用户姓名:
      </el-col>
     <el-col :span="7">
       
            <el-input :readonly="is_modifly" v-model="name" placeholder="请输入用户姓名"></el-input>
          
      </el-col>
    </el-row>
     <el-row class="myMarginTop_10px">
      <el-col :span="3" class="myLeftMsg">
        
         身份证号码:
      </el-col>
      <el-col :span="7">
       
            <el-input :readonly="is_modifly" v-model="idcard_number" placeholder="请输入身份证号码"></el-input>
          
      </el-col>
    </el-row>
     
    <el-row class="myMarginTop_10px">
      <el-col :span="7" :offset="3">
        <!--<el-button type="primary" class="myBgGreen" v-if="type=='update'" @click="onEditAd">保 存</el-button>
        <el-button type="primary" class="myBgGreen" v-if="type=='add'" @click="onCreate">权限下放</el-button>-->
        <el-button type="primary" class="myBgGreen" @click="onBack">返 回</el-button>
      </el-col>
    </el-row>
  </el-form>  
    
  </div>
</template>
<style scoped>
  .myContainer{
    background: #fff;
    padding: 10px;
  }
  .myTitleBorderBottom{
    color: #000;
    font-weight: 500;
    font-size: 16px;
    border-bottom: 1px solid #dbdbdb;
  }
  .myBgGreen{
    background: #00c2a9;
    border-color: #00c2a9;
    color: #fff;
    margin-top:2px;
  }
  .myBgGreen:hover{
    background: #33ceba;
  }
  .myTextAlignRight{
    text-align: right;
  }
  .myLineHeight_40px{
    line-height: 40px;
  }
  .myMarginTop_10px{
    margin-top: 10px;
  }
  .myLeftMsg{
    line-height: 40px;
    text-align: right;
    padding-right: 10px;
  }
  .myMarginTop_10px{
    padding-bottom: 10px;
  }
  .myVA_M{
    vertical-align: middle;
  }
  .myMarginBottom_10px{
    margin-bottom: 20px;
  }
  .avatar-uploader .el-upload {
    border: 1px dashed #d9d9d9;
    border-radius: 6px;
    cursor: pointer;
    position: relative;
    overflow: hidden;
  }
  .avatar-uploader .el-upload:hover {
    border-color: #409EFF;
  }
  .avatar-uploader-icon {
    font-size: 28px;
    color: #8c939d;
    width: 178px;
    height: 178px;
    line-height: 178px;
    text-align: center;
    border:1px solid #d8dce5;
  }
  .avatar {
    width: 178px;
    /*height: 178px;*/
    display: block;
  }
</style>
<script>
	import { EBIZ_API } from '@/config/baseUrl';
  import { getJumpValue , addAd , getAd , editAd } from '@/api/online';
  import { getUserDetail } from '@/api/entrance_guard';
  import { r_email , r_phone } from "@/api/regular";//正则
  
  export default {
    data(){
      return{
        title: "门禁用户管理",
        id: "",
        is_modifly:false,
        type:"",
        idcard_number:"",
        name:"",
        sex:"",
        area_name:"",
        imageUrl:"",
        saveImageUrl:"",
        responseUrl:EBIZ_API+'/appAdmin_pictures/save.do?pictype=adpic',//上传图片的地址url
        ic_number:"",
        visible_light_pic:"",       
        login_name:"",
        person_id:"",
         detail:{
          
        },                   
        ad_jumpValue:"",
            
        ADDESC:"",
        startTime:"",
        endTime:"",       
       
        rules: {
         
          card_no:[
            {required: true, message: '不能为空！', trigger: 'blur'},
            
            ],          
          },
      }
    },
    components: {
        
    },
    created(){
      document.title=this.title;
      this.type = this.$route.query.type;
      this.id = this.$route.query.id;
      if(this.type=='add'){

      }
      if(this.type=='info'){
        this.onGetAd();
        this.is_modifly = true;
      }
      
    },
    methods:{     
      onEditAd(){
        let vm=this;
        let params={          
          ADDESC:vm.ADDESC,
         
        }
        editAd(params).then(response => {
          // console.log("修改成功")
          this.$message.success('执行成功！');
          this.$router.go(-1);
        }).catch(error => {
          this.$message.error('执行失败！');
          // console.log("修改失败")
        })
      },
       handleAvatarSuccess(res, file) {
        this.imageUrl = URL.createObjectURL(file.raw);
        this.saveImageUrl=res.saveUrl;
      },
      beforeAvatarUpload(file) {
        const isJPG = file.type === 'image/jpeg';
        const isPNG = file.type === 'image/png';
        const isLt2M = file.size / 1024 / 1024 < 2;
        if (!isJPG && !isPNG) {
          this.$message.error('上传图片只能是 JPG/PNG 格式!');
        }
        if (!isLt2M) {
          this.$message.error('上传图片大小不能超过 2MB!');
        }
        return (isJPG || isPNG) && isLt2M;
      },
      onCreate(){//添加
        let vm=this;
        let params={
        
          ADDESC:vm.ADDESC,
        }
        addAd(params).then(response => {
          let res=response.data;
          vm.$message.success("添加数据成功！");
          this.$router.go(-1);
          // console.log("添加成功",res);
        }).catch(error => {
          vm.$message.error("添加数据失败！");
          // console.log("添加失败",error);
        })
        // console.log(params)
      },
      onBack(){//返回
      	let vm =this;
      	window.localStorage.setItem('pageNum',vm.$route.query.pageNum||1);
        this.$router.go(-1);
      },
      
      onGetAd(){//拉取
        let vm=this;
        
        getUserDetail(vm.id).then(response => {
          let res=response.data;
          vm.idcard_number=res.idcard_number;
          vm.name=res.name;
          vm.sex=Number(res.sex);
          vm.area_name=res.area_name;
          vm.ic_number=res.ic_number;
          vm.imageUrl=res.visible_light_pic;
          vm.login_name=res.login_name;
          vm.person_id=res.person_id;
        }).catch(error => {
          console.log("拉取数据失败",error);
        })
      } 
      

    }
  
  }


</script>



